Wikipedia Article Fetcher

import wikipedia def fetch_article(topic): try: print(f"\nšŸ” Searching for '{topic}'...") summary = wikipedia.summary(topic, sentences=3) page = wikipedia.page(topic) print("\nšŸ“˜ Summary:") print(summary) print("\nšŸ”— URL:", page.url) more = input("\nDo you want to read the full article? (y/n): ").strip().lower() if more == 'y': print("\nšŸ“„ Full Content:\n") print(page.content[:2000] + '...') # Show first 2000 characters except wikipedia.exceptions.DisambiguationError as e: print("ā— Disambiguation error. Please be more specific.") print("Options include:", e.options[:5]) # Show top 5 suggestions except wikipedia.exceptions.PageError: print("āŒ Page not found. Please check the topic spelling.") except Exception as e: print(f"āš ļø Error: {e}") def main(): print("--- Wikipedia Article Fetcher ---") topic = input("Enter a topic to search: ").strip() fetch_article(topic) if __name__ == "__main__": main()

Code output

--- Wikipedia Article Fetcher --- Enter a topic to search: Python programming šŸ“˜ Summary: Python is a high-level, general-purpose programming language. Its design philosophy emphasizes code readability... šŸ”— URL: https://en.wikipedia.org/wiki/Python_(programming_language) Do you want to read the full article? (y/n): n